# 也叫做三目运算

"""
也叫做 三目运算

将多层的结构变为一层，先对【条件】进行判断，【条件成立】返回值1；否则返回值2

三元运算，一般是用来单独设置一个值

由于只是为了赋值，并没有复杂的代码段，所以就有了三元运算
"""

lst = []

if len(lst): # if lst
    a = lst[0]
else:
    a = 2
print(a)
b = lst[0] if len(lst) else 123
print(b)

data = {
    "name": "木舟",
    "sex": "male"
}

# if "name" in data.keys():
#     name = data['name']
# else:
#     name = "muzhou"
#
# if "sex" in data.keys():
#     sex = data['sex']
# else:
#     sex = "male"


# dic = {
#     "name": data['name'] if "name" in data.keys() else "muzhou",
#     "sex": data['sex'] if "sex" in data.keys() else "male",
# }
# print(dic)